<?php
/**
 * 公共后台类
 * @Author hugo
 * @Email webmaster@jushare.com
 */
namespace Common\Controller;
use Think\Controller;

abstract class CpanelController extends Controller
{
    protected $mode;//当前数据模型

    function _initialize(){
        //TODO 验证权限
    }

    public function index(){
        $this->display();
    }

    /**
     * 保存记录
     */
    public function save(){
        $data = self::$mode->create();
        $primary = self::$mode->getPk();

        if(empty($data[$primary])){
            $result = self::$mode->add();
        }else{
            $result = self::$mode->save();
        }

        if($result){
            $this->success(L('save_success'));
        }else{
            $this->error(L('save_error'));
        }
    }
}